package com.atguigu.gmall.product.controller;
import com.atguigu.gmall.model.product.BaseAttrInfo;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.extension.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@CrossOrigin
@RequestMapping("/admin/product")
public class ManageController {

    @Autowired
    private ManageService manageService;


    /**
     * 获取一级分类
     * @return
     */
    @GetMapping("/getCategory1")
    public R getCategory1(){
        return R.ok(manageService.getCategory1());
    }

    /**
     * 获取一级分类
     * @return
     */
    @GetMapping("/getCategory2/{category1Id}")
    public R getCategory2(@PathVariable("category1Id")Long  category1Id){
        return R.ok(manageService.getCategory2(category1Id));
    }

    /**
     * 获取三级分类
     * @return
     */
    @GetMapping("/getCategory3/{category2Id}")
    public R getCategory3(@PathVariable("category2Id")Long  category2Id){
        return R.ok(manageService.getCategory3(category2Id));
    }

    /**
     * 根据分类id获取平台属性
     * @param category1Id
     * @param category2Id
     * @param category3Id
     * @return
     */
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public R selectAttrInfoList(@PathVariable("category1Id")Long category1Id,
                                @PathVariable("category2Id")Long category2Id,
                                @PathVariable("category3Id")Long category3Id){
        List<BaseAttrInfo> baseAttrInfoList = manageService.selectAttrInfoList(category1Id, category2Id, category3Id);
        return R.ok(baseAttrInfoList);
    }

    @PostMapping("/saveAttrInfo")
    public R saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        manageService.saveAttrInfo(baseAttrInfo);
        return null;
    }

}
